package chat_server;

// -----------------------------------------------------------------------------
// Importanweisungen
import for_all.Transporter;
import for_all.User;
import java.net.*;


public class ClientHandler extends Thread {
    
    // -------------------------------------------------------------------------
    // Variablendeklarationen
    private Transporter transporter;
    private ManageUser  users;
    private ManageRooms  rooms;
    
    
    // -------------------------------------------------------------------------
    // Konstruktor
    ClientHandler(Socket socket, ManageUser users, ManageRooms mangRms) {
        
            this.transporter = new Transporter(socket);
            this.users = users;
            this.rooms = mangRms;
    }
    
    
    // -------------------------------------------------------------------------
    // Thread zum Verarbeiten von eingehenden Netzwerkkommunikationen
    @Override
    public void run() {
            
        boolean success = false;   
            
        while(!success) {
            Object receivedObject = this.transporter.receiveObject();
                
            // LogIn
            if (receivedObject instanceof User) {        
                if (users.logIn((User) receivedObject, this.transporter, rooms)) {
                    success = true;
                }
            }   
        }
    }
}